#include <QtEndian>
#include "basersuctrl.h"

BaseRsuCtrl::BaseRsuCtrl(QObject *parent) : QObject(parent)
{
    memset(m_BeaconId, 0, 4);
    m_bstInterval=10;
    m_rsuPower=0;
    m_rsuChannel=0;
    m_nRsuHeartBeatCheckStyle=0;
    m_nHeartBeatCheckInterval=120*1000;
    m_status=DEV_STATUS_INIT;
    m_nNoResponseErrorCount=0;
    m_nBeaconChangeInterval=0;
}

BaseRsuCtrl::~BaseRsuCtrl()
{

}

void BaseRsuCtrl::fillCurrentTime(quint8 *Time)
{
    quint32 uTime = QDateTime::currentDateTime().toTime_t();
    uTime=qToBigEndian(uTime);
    memcpy(Time, &uTime, 4);
}

int BaseRsuCtrl::initRsu(int nBSTInterval, int nTxPower, int nPLLChannelID)
{
    configBstInterval(nBSTInterval);
    configRsuPower(nTxPower);
    configRsuChannel(nPLLChannelID);
    return initRsu();
}

void BaseRsuCtrl::tryReconnect()
{
    this->setStatus(DEV_STATUS_ERR);
    this->closeRsu();
    this->reopenRsu();
}

void BaseRsuCtrl::modifyBeaconId()
{
    if (0==m_nBeaconChangeInterval)
    {
        return;
    }
    static quint64 nLastCheck=0;
    quint64 nCurrentCheck=QDateTime::currentMSecsSinceEpoch()/m_nBeaconChangeInterval;
    if (nLastCheck!=nCurrentCheck)
    {
        nLastCheck=nCurrentCheck;
        m_BeaconId[2]=m_BeaconId[2]+1;
        m_BeaconId[3]=m_BeaconId[3]-1;
    }
}





